package com.huanletao.quartz.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * <p>
 *
 * </p>
 *
 * @package: com.huanletao.quartz
 * @description:
 * @className: SpringUtils
 * @author: @踏雪无痕
 * @date: Created in 2022/7/1
 * @copyright: Copyright (c) 2022/7/1 21:11
 * @version: V1.0
 */
@Component
public class SpringUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    /**
     *
     *
     *
     * @return
     */
    @SuppressWarnings("all")
    public static <T> T getBean(String beanName){
        return (T) applicationContext.getBean(beanName);
    }

    public static<T> T getBean(Class<T> tClass){
        return applicationContext.getBean(tClass);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringUtils.applicationContext = applicationContext;
    }
}
